import React from "react";
import {ScrollView, View} from "react-native";
import chjStyle from "../../../CustomStyle";
import ModuleCommonHeader from "../../../main/module/ModuleCommonHeader";
import CommonTextItem from "../../../main/record/common/CommonTextItem.js";
import SingleSelectionTextItem from "../../../main/record/common/SingleSelectionTextItem.js";
import InputTextItem from "../../../main/record/common/InputTextItem.js";
import SwitchTextItem from "../../../main/record/common/SwitchTextItem.js";
import CommonMultiListSelection from "../../../main/record/common/CommonMultiListSelection.js";
import Util from "../../../main/Util.js";
import NextButton from "../../../main/record/common/NextButton";
import {Actions} from "react-native-router-flux";

export default class HelpCarEngine extends React.Component {
    // 构造函数，可执行初始化操作
    constructor(props) {
        super(props);
        // 在ES6，在构造函数里初始化state
        this.state = {};
        const {carData} = props;
        if (!carData.carengine) {
            carData.carengine = Util.defaultCarengine();
        }
    }

    // 组件被加载时
    componentDidMount() {

    }

    // 组件即将被卸载时
    componentWillUnmount() {
    }

    // 组件被渲染时
    render() {
        const {carData} = this.props;
        return (
            <View style={chjStyle.mainContainer}>
                <ModuleCommonHeader title='车辆引擎舱(05)' clickedLeft={this.clickedBack.bind(this)} leftText='返回'
                                    clickedRight={this.clickedNew.bind(this)} rightText='保存'/>
                <ScrollView
                    style={chjStyle.mainList}>
                    {
                        carData.carengine.map((item, i) => this.renderItem(item, i))
                    }
                </ScrollView>
                <NextButton onClickedListener={() => this.clickedNew()}/>
            </View>
        );
    }

    renderItem(item, i) {
        if (i <= 11) {
            return (<SingleSelectionTextItem object={item} optionArray={[{name: "无"}, {name: "轻微"}, {name: "严重"}]}/>);
        }
        else if (i <= 16) {
            return (<SingleSelectionTextItem object={item} optionArray={[{name: "正常"}, {name: "缺少"}, {name: "偏高"}]}/>);
        }
        else if (i === 17) {
            return (<SingleSelectionTextItem object={item} optionArray={[{name: "正常"}, {name: "异常"}]}/>);
        }
        else {
            return (
                <InputTextItem object={item} autoCapitalize={'characters'} keyboardType={'default'} maxLength={19}/>);
        }
    }

    clickedBack() {
        Actions.pop();
    }

    clickedNew() {
        const {saveKey, carData} = this.props;
        Util.saveData(saveKey, carData);
        Actions.HelpCarCockpit(
            {
                saveKey,
                carData
            }
        );
    }
}
